﻿using Infrastructure.Web;
using MyData.Dto;
using MyData.Models;
using MyWeb.App_Start;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyWeb.Controllers
{
    public class MeetController : BaseController
    {
        // GET: Meet
        [HandlerLogin]
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetMeetList(QueryListModel query, string Name)
        {
            var result = MeetApp.GetMeetList(query, Name);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        [HandlerLogin]
        public ActionResult MeetView(string id)
        {
            if (!String.IsNullOrEmpty(id))
            {
                var entity = MeetApp.GetMeetDto(Guid.Parse(id));
                return View(entity);
            }
            return View(new MeetDto());

        }
        [HttpPost]
        public JsonResult SaveMeet(string Id, string MeetName, string MeetRemark)
        {
            return base.Try(() =>
            {
                Meet meet = new Meet();

                meet.MeetName = MeetName;
                meet.MeetRemark = MeetRemark;
                if (!String.IsNullOrEmpty(Id)&&Id!=Guid.Empty.ToString())
                {
                    meet.Id = Guid.Parse(Id);
                    MeetApp.UpdateMeet(meet);
                }
                else
                {
                    MeetApp.AddMeet(meet);
                }

              
            });
        }
        [HttpPost]
        public JsonResult MeetDelete(string Id)
        {
            return base.Try(() =>
            {
                MeetApp.DeleteMeet(Guid.Parse(Id));
            });

        }
        [HttpPost]
        public JsonResult ClearMeet(string Id)
        {
            return base.Try(() =>
            {
                MeetApp.ClearMeet(Guid.Parse(Id));
            });

        }
    }
}